/**
 * Desktop Like Interface WindowContainer
 * copyrigth djayux
 * GPL-2.0
 * gerald@djayux.net
 *
 */

var req=new Array();
var name=new Array();

function remove(id,arr){
  tmp=Array();
  for(i=0;i<arr.length;i++)
    if(i!=id)
      tmp=arr[i];
  return tmp;
}

function pause(numberMillis) {
  var now = new Date();
  var exitTime = now.getTime() + numberMillis;
  while (true) {
    now = new Date();
    if (now.getTime() > exitTime)
      return;
  }
}

      
function WindowContainer(n,size,coord){

  this.datype='WindowContainer';
  this.init();
  
  this.id=name.length;
  this.name=n[0];
  name[this.id]=this.name;

  this.title=n[1];
  this.width=size[0];
  this.height=size[1];
  this.coord_x=coord[0];
  this.coord_y=coord[1];
  this.request=null;
  eval(this.name+'Win=new Window("'+this.name+'Win")');
  this.window=eval(this.name+'Win');

  var root=document.body;
  var el = document.createElement('div');
  el.setAttribute('style', 'width:'+this.width+'px;');
  el.setAttribute('class', 'win');
  el.setAttribute('onclick', this.window.name+".setImg(this);");
  el.setAttribute('id', this.name+'Win');
  var el1 = document.createElement('div');
  el1.setAttribute('class', 'title');
  el1.setAttribute('id', this.name+'WinTitle');
  title=document.createTextNode(this.title);
  el1.appendChild(title);
  imgH=document.createElement('img');
  imgH.setAttribute('class', 'first');
  imgH.setAttribute('src', './images/minimize.png');
  imgH.setAttribute('onclick', this.window.name+".displayContent();");
  el1.appendChild(imgH);
  imgH=document.createElement('img');
  imgH.setAttribute('class', 'second');
  imgH.setAttribute('id', this.name+'Winmaximize');
  imgH.setAttribute('src', './images/maximize.png');
  imgH.setAttribute('onclick', this.window.name+".setFullScreen();");
  el1.appendChild(imgH);
  imgC=document.createElement('img');
  imgC.setAttribute('class', 'last');
  imgC.setAttribute('src', './images/close.png');
  imgC.setAttribute('onclick', this.window.name+".hide();");
  el1.appendChild(imgC);
  el.appendChild(el1);
  var content = document.createElement('div');
  content.setAttribute('class', 'wcontent');
  content.setAttribute('style', 'height:'+this.height+'px;');
  content.setAttribute('id', this.name+'WinC');
  el.appendChild(content);
  content1 = document.createElement('div');
  content1.setAttribute('class', 'wstatus');
  content1.setAttribute('style', 'position: absolute;top: '+(this.height+17)+'px;left: 0px;height:15px;width: '+(this.width-6)+'px;');
  content1.setAttribute('id', this.name+'WinStatus');
  content1.appendChild(document.createTextNode('en attente'));
  content2 = document.createElement('div');
  content.appendChild(content1);
  content2.setAttribute('class', 'resizer');
  //content2.setAttribute('src', './images/resizer.gif');
  content2.setAttribute('style', 'position: absolute;top: '+(this.height+19)+'px;left: '+(this.width-16)+'px;');
  content2.setAttribute('id', this.name+'WinResizer');
  content2.setAttribute('onclick', this.name+'Win.setResizerImg(this)');
  content2.setAttribute('onmousedown', this.name+'Win.setResizerImg(this)');
  content.appendChild(content2);
  root.appendChild(el); 

  this.status=document.getElementById(this.name+'WinStatus');
  this.content=null;
     
}

WindowContainer.prototype=new Controler();

/**
 * Attribut content, contenue de la fenêtre
 */
/**
 * @param content string
 */
WindowContainer.prototype.setContent=function(content){
  this.content=content;
  eval('document.'+this.name+'C.innerHTML='+content+';');
}

WindowContainer.prototype.newData=function() {
  try{
    document.getElementById(this.name+'WinC').innerHTML+=this.request.responseText;
    document.getElementById(this.name+'WinStatus').innerHTML="Terminé.";

    now1=new Date();
    this.timeStamp.setMinutes(this.timeStamp.getMinutes(),this.timeStamp.getSeconds()-35,this.timeStamp.getMilliseconds());

    this.timeStamp.setMinutes(now1.getMinutes()-this.timeStamp.getMinutes(),now1.getSeconds()-this.timeStamp.getSeconds(),now1.getMilliseconds()-this.timeStamp.getMilliseconds());

    document.getElementById(this.name+'WinStatus').innerHTML+="("+(this.timeStamp.getSeconds())+" s "+(this.timeStamp.getMilliseconds())+" ms)";

    this.request=null;
  }
  catch(e) {
    document.getElementById(this.name+'WinStatus').innerHTML="There was a problem retrieving the XML data:\n" +this.request.statusText+" "+e;
  }
}

